package org.grow.yc.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.grow.yc.dao.LeaveBillMapper;
import org.grow.yc.entity.LeaveBill;
import org.grow.yc.entity.LeaveQueryCondition;
import org.grow.yc.entity.QueryCondition;
import org.grow.yc.filter.AuthInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: xwg
 * @CreateDate: 2024/9/4
 */

@RestController
@RequestMapping("/leaveBill")
public class LeaveBillController {
    @Autowired
    private LeaveBillMapper leaveBillMapper;

    @GetMapping("/query")
    public List<LeaveBill> query() {
        return leaveBillMapper.selectSome();
    }
    @PostMapping("/queryPage")
    public IPage<LeaveBill> queryPage(@RequestBody QueryCondition queryCondition) {

        System.out.println(queryCondition);
        Page<LeaveBill> page = Page.of(queryCondition.getPageNum(), queryCondition.getPageSize());
        return leaveBillMapper.selectSome(page);
    }
    @PostMapping("/queryPage2")
    public IPage<LeaveBill> queryPage2(@RequestBody LeaveQueryCondition qc) {

        System.out.println(qc);
        Page<LeaveBill> page = Page.of(qc.getPageNum(), qc.getPageSize());
        return leaveBillMapper.selectSome2(page,qc);
    }

    @GetMapping("/{id}")
    public LeaveBill find(@PathVariable("id") String id) {

        Integer i = Integer.parseInt(id);

        return leaveBillMapper.findById(i);

    }

    @PostMapping("/insert")
    public LeaveBill insert(@RequestBody LeaveBill leaveBill) {
        leaveBill.setBillId(0);;
        leaveBillMapper.insert(leaveBill);
        return leaveBill;
    }

}
